package lab2;
/**
 * Title: ASimpleGUI class for CSIS 235 Lab 2
 * Description: CS 235 Lab #1 - example program
 *    Basic (not very object-oriented) GUI program used to show how to draw shapes.
 * 
 * @author Anthony Varghese
 * @email anthony.varghese@uwrf.edu
 * @date September 6th 2012
 */
import javax.swing.JFrame;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Ellipse2D;

public class ASimpleGUI {
	/*
	 * Data members used to initialize a window.
	 */
	private static final String TITLE = "Lab 2: first GUI program";
	private static final int FRAME_LOCATION_X = 100;
	private static final int FRAME_LOCATION_Y = 200;
	private static final int FRAME_SIZE_X     = 400;
	private static final int FRAME_SIZE_Y     = 300;
	
	/*
	 * Data members used to set the sizes of shapes to
	 * be drawn inside the window.
	 */
	private static final float SHAPE_LOCATION_X = 150.0f;
	private static final float SHAPE_LOCATION_Y = 75.0f;
	private static final float SHAPE_SIZE_X     = 200.0f;
	private static final float SHAPE_SIZE_Y     = 100.0f;
	
	
	/**
	 * main method - this is the "big main" style of programming
	 * @param args
	 */
	public static void main(String[] args) {
		/*
		 * Create a JFrame object, set the location on screen and size
		 *  and make it visible.
		 */
		JFrame window = new JFrame( TITLE );
		window.setLocation( FRAME_LOCATION_X, FRAME_LOCATION_Y );
		window.setSize( FRAME_SIZE_X, FRAME_SIZE_Y );
		window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		window.setVisible( true );
		
		// At this point, the window should be visible.
		// Now we are ready to draw shapes.
		Shape s = new Rectangle2D.Float( SHAPE_LOCATION_X, SHAPE_LOCATION_Y, SHAPE_SIZE_X, SHAPE_SIZE_Y );
		
		// OK, we have a rectangle set up. Let's draw it.
		
		// It would be nice to draw the shape right in the JFrame window we created.
		// Unfortunately, we cannot do that because of the way we set up the the window above!
		
		// We have to set up a class that can be used to draw the shape
		class DrawArea extends javax.swing.JComponent{
			private Shape shape;
			/**
			 * paintComponent:
			 * The paintComponent method is called whenever the Java runtime system thinks
			 * it needs to draw or redraw something.
			 */
			public void paintComponent(Graphics g){
				Graphics2D g2d = (Graphics2D) g;
				g2d.draw( shape );
			}
			/*
			 * set method to set shape data member
			 */
			public void setShape(Shape s){
				shape = s;
			}
		}
		
		// Then, we create an instance of the above class
		DrawArea area = new DrawArea();
		area.setShape( s );
		
		// And we have to "add" the DrawArea object to our window.
		window.add( area );
		
		/*
		 *  This next line of code pauses the program for 2 seconds so that we
		 *   can see things changing in the window. You can leave this code alone.
		 */
		try { Thread.sleep( 1000 /* milliseconds */ ); } catch (InterruptedException e) {	}
		
		/*
		 *  Let's draw an oval shape. We have to create the new shape and add it to the
		 *   "drawing area" and ask the window to repaint itself - Swing will cause
		 *   the DrawArea to "refresh" itself.
		 */
		s = new Ellipse2D.Float( SHAPE_LOCATION_X, SHAPE_LOCATION_Y, SHAPE_SIZE_X, SHAPE_SIZE_Y );
		area.setShape( s );
		window.repaint();
		
		/*
		 *  Here's where you want to add code to to draw two more new shapes.
		 */

		
		
		
		/*
		 *  And, finally, add code that will make the shapes move around smoothly
		 *   for about 5 seconds inside the window
		 */
		
		
	}
}